from django.shortcuts import redirect
from django.urls import reverse


class LoginMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        whiteList = ['/admin/login/', '/admin/', reverse('store_system:login'), reverse('store_system:register')]
        path = request.path
        if path in whiteList or request.user.is_authenticated:
            response = self.get_response(request)
            return response
        else:
            return redirect(reverse('store_system:login'))